package com.mvc.controller;

import com.mvc.annotation.Autowired;
import com.mvc.annotation.Controller;
import com.mvc.annotation.RequestMapping;
import com.mvc.annotation.Security;
import com.mvc.model.Result;
import com.mvc.service.IUserService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Kirito
 * @description:
 * @date 2020/04/10
 */
@Controller
@RequestMapping("/users")
public class UserController {

    @Autowired
    private IUserService userService;

    /**
     * sayHello支持所有人访问
     *
     * @param req      HttpServletRequest
     * @param resp     HttpServletResponse
     * @param username String
     * @return Result
     * @throws Exception Exception
     */
    @RequestMapping("/hello")
    public Result sayHello(HttpServletRequest req, HttpServletResponse resp, String username) throws Exception {
        String message = userService.sayHello(req, resp, username);
        Result result = new Result();
        result.setStatus("200");
        result.setMessage(message);
        return result;
    }

    @Security("admin")
    @RequestMapping("/admin")
    public Result admin(HttpServletRequest req, HttpServletResponse resp, String username) throws Exception {
        Result result = new Result();
        result.setStatus("200");
        result.setMessage("Dear " + username + "! You are god!!");
        return result;
    }

    @Security(value = {"vip", "admin"})
    @RequestMapping("/vip")
    public Result vip(HttpServletRequest req, HttpServletResponse resp, String username) throws Exception {
        Result result = new Result();
        result.setStatus("200");
        result.setMessage("Dear " + username + "! 30 days left for your member, please recharge in time..");
        return result;
    }

    @Security(value = {"vip", "admin", "guest"})
    @RequestMapping("/guest")
    public Result guest(HttpServletRequest req, HttpServletResponse resp, String username) throws Exception {
        Result result = new Result();
        result.setStatus("200");
        result.setMessage("Dear " + username + "! Welcome to this website , please register first!!");
        return result;
    }
}
